package com.app.h5.util;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.view.Window;

import com.app.h5.R;
import com.app.h5.databinding.BottomShareLayoutBinding;

import androidx.annotation.NonNull;


public class BottomMediaDialog extends Dialog {

    private final BottomShareLayoutBinding binding;

    @SuppressLint("InflateParams")
    public BottomMediaDialog(@NonNull Context context, SelectListener selectListener) {
        super(context, R.style.dialog_bottom);
        binding = BottomShareLayoutBinding.inflate(LayoutInflater.from(context));
        setContentView(binding.getRoot());
        setCanceledOnTouchOutside(false);
        Window window = getWindow();//设置窗体位置以及动画
        if (null != window) {
            window.setWindowAnimations(R.style.main_menu_animstyle);
            window.setGravity(Gravity.BOTTOM);
            window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        binding.tvPic.setOnClickListener(v -> {
            dismiss();
            if (selectListener != null) {
                selectListener.pic();
            }
        });
        binding.tvVideo.setOnClickListener(v -> {
            dismiss();
            if (selectListener != null) {
                selectListener.video();
            }
        });
       /* setOnDismissListener(dialog -> {
            if (selectListener != null) {
                selectListener.cancel();
            }
        });*/
        binding.tvCancel.setOnClickListener(v -> {
            dismiss();
            if (selectListener != null) {
                selectListener.cancel();
            }
        });
    }

    public interface SelectListener {
        void pic();

        void video();

        void cancel();
    }
}
